home *** CD-ROM | disk | FTP | other *** search
- /*
-
- SolveRubiksCube
- Copyright (c) 1994 J Robert Boonstra
-
- */
-
- #pragma options(honor_register,assign_registers)
-
- #include "rubik.h"
- #include "transform.h"
-
- Boolean SolveBottomEdges(register RubiksCube *rub)
- {
- short loopCount;
-
- /**********************************************************
- *
- * STEP 6: Move edge cubes in bottom layer into position.
- *
- *********************************************************/
- if (DF_F == F || DF_D == F) { /* FD in pos */
- if (DL_L == R || DL_D == R) { /* BD->LD->RD->BD */
- B2D1R3L1B2R1L3D1B2;
- } else if (DR_R == L || DR_D == L) {/* BD->RD->LD->BD */
- B2D3R3L1B2R1L3D3B2;
- }
- } else if (DL_L == L || DL_D == L) { /* LD in pos */
- if (DB_B == F || DB_D == F) { /* RD->BD->FD->RD */
- R2D1F3B1R2F1B3D1R2;
- } else if (DF_F == B || DF_D == B) {/* RD->FD->BD->RD */
- R2D3F3B1R2F1B3D3R2;
- }
- } else if (DR_R == R || DR_D == R) { /* RD in pos */
- if (DF_F == B || DF_D == B) { /* LD->FD->BD->LD */
- L2D1B3F1L2B1F3D1L2;
- } else if (DB_B == F || DB_D == F) {/* LD->BD->FD->LD */
- L2D3B3F1L2B1F3D3L2;
- }
- } else if (DB_B == B || DB_D == B) { /* BD in pos */
- if (DR_R == L || DR_D == L) { /* FD->RD->LD->FD */
- F2D1L3R1F2L1R3D1F2;
- } else if (DL_L == R || DL_D == R) {/* FD->LD->RD->FD */
- F2D3L3R1F2L1R3D3F2;
- }
- } else {
- /* There are no edges in their proper place. */
- if (DF_F == L || DF_D == L) {
- F1L1D1L3D3F2R3D3R1D1F1;
- } else if (DF_F == B || DF_D == B) {
- R2L2U1R2L2D2R2L2U1R2L2;
- } else if (DF_F == R || DF_D == R) {
- R1F1D1F3D3R2B3D3B1D1R1;
- }
- }
-
- /**********************************************************
- *
- * STEP 7: Flip edges in bottom layer.
- *
- *********************************************************/
- loopCount = 0;
- do {
- if (++loopCount > 24) return false;
- /*
- * At this point, all the edge cubes in the bottom layer
- * are in the correct positions, but perhaps not in the
- * correct orientation.
- *
- * Exit if all edge cubes have the proper orientation.
- */
- if (DF_F == F && DR_R == R &&
- DB_B == B && DL_L == L)
- break;
- /*
- * At least one edge cubes does not have the proper
- * orientation. The cube has the property that an even
- * number of edge cubes need to be flipped.
- */
- if (DF_F == D) {
- if (DL_L == D) {
- F1D1U3R2D2U2L1D1L3U2D2R2U1D3F3D3;
- } else if (DB_B == D) {
- F1D1U3R2D2U2L1D2L3U2D2R2U1D3F3D2;
- } else if (DR_R == D) {
- F1D1U3R2D2U2L1D3L3U2D2R2U1D3F3D1;
- }
- } else if (DL_L == D) {
- if (DB_B == D) {
- L1D1U3F2D2U2B1D1B3U2D2F2U1D3L3D3;
- } else if (DR_R == D) {
- L1D1U3F2D2U2B1D2B3U2D2F2U1D3L3D2;
- } else if (DF_F == D) {
- L1D1U3F2D2U2B1D3B3U2D2F2U1D3L3D1;
- }
- } else if (DB_B == D) {
- if (DR_R == D) {
- B1D1U3L2D2U2R1D1R3U2D2L2U1D3B3D3;
- } if (DF_F == D) {
- B1D1U3L2D2U2R1D2R3U2D2L2U1D3B3D2;
- } else if (DL_L == D) {
- B1D1U3L2D2U2R1D3R3U2D2L2U1D3B3D1;
- }
- } else if (DR_R == D) {
- if (DF_F == D) {
- R1D1U3B2D2U2F1D1F3U2D2B2U1D3R3D3;
- } else if (DL_L == D) {
- R1D1U3B2D2U2F1D2F3U2D2B2U1D3R3D2;
- } else if (DB_B == D) {
- R1D1U3B2D2U2F1D3F3U2D2B2U1D3R3D1;
- }
- }
- } while(true);
- return (true);
- }